package com.hotel.controller;

import com.hotel.entity.Menu;
import com.hotel.entity.Room;
import com.hotel.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class MenuController {
    @Autowired
    private MenuService menuService;
    //增
    @PostMapping("/admin/menuitems")
    public void save(@RequestBody Menu menu) {
        menuService.save(menu);
    }
    //查
    @GetMapping({"/admin/menuitems","/client/menuitems"})
    public List<Map<String, Object>> findAll() {
        return menuService.findAll();
    }
    //改
    @PutMapping("/admin/menuitems/{id}")
    public void update(@PathVariable("id") Integer id, @RequestBody Menu menu) {
        menuService.update(id, menu);
    }
    //删
    @DeleteMapping("/admin/menuitems/{id}")
    public void delete(@PathVariable("id") Integer id) {
        menuService.delete(id);
    }
    //批量导入
    @PostMapping("/admin/menuitems/import")
    public ResponseEntity<Map<String, Object>> batchSave(@RequestBody List<Menu> menus) {
        int importedCount = 0;
        for (Menu menu : menus) {
            menuService.save(menu);
            importedCount++;
        }
        Map<String, Object> response = new HashMap<>();
        response.put("message", "成功导入");
        response.put("importedCount", importedCount);
        return ResponseEntity.ok(response);
    }


}
